<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * 微信配置文件
 * @author Mk
 */
class WxSystem extends Admin_Controller{
	function __construct()
	{
		parent::__construct();
		$this->load->model(array('WxConfig_model'));
	}
	function index(){
		$data_info = $this->WxConfig_model->get_one(array("id"=>1));
		$this->view('index',array('data_info'=>$data_info,'require_js'=>true));
	}
	function edit($id=0){
		$id = intval($id);
		
		$data_info =$this->WxConfig_model->get_one(array('id'=>$id));
		
		//如果是AJAX请求
		if($this->input->is_ajax_request())
		{
			if(!$data_info)exit(json_encode(array('status'=>false,'tips'=>'信息不存在')));
				$appid = trim($_POST['appid']);
				$secret = trim($_POST['secret']);
				if($appid=="")exit(json_encode(array('status'=>false,'tips'=>'appid不能为空')));
				if($secret=="")exit(json_encode(array('status'=>false,'tips'=>'secret不能为空')));
				$status = $this->WxConfig_model->update(
						array(
								'appid'=>$appid,
								'secret'=>$secret,
						),array('id'=>$id));
				if($status)
				{
					exit(json_encode(array('status'=>true,'tips'=>'修改成功')));
				}else
				{
					exit(json_encode(array('status'=>false,'tips'=>'修改失败')));
				}
		}else
		{
			if(!$data_info)$this->showmessage('信息不存在');
			$this->view('edit',array('is_edit'=>true,'data_info'=>$data_info,'require_js'=>true));
		}
	}
}
